'use strict';

var express = require('express');
var session = require('express-session'); //如果要使用session，需要单独包含这个模块
var cookieParser = require('cookie-parser'); //如果要使用cookie，需要显式包含这个模块
var bodyParser = require('body-parser');
var path = require('path');
var mongoose = require('mongoose'); //芒果数据库
var port=process.env.PORT || 3000; //端口
var dbUrl = 'mongodb://localhost/bigcms';

var app = express();
app.use(session({
  resave:false,
  saveUninitialized:false,
  secret: 'keyboard cat'
}))

//设置模板
app.set('view engine', 'html');
var nunjucks = require('nunjucks');
nunjucks.configure(path.join(__dirname, './app/views'), {
    path:path.join(__dirname, './app/views'),
    autoescape: true,
    express: app
});

//静态资源路径
app.use(express.static(path.join(__dirname,'public')));
app.use(bodyParser.urlencoded({ extended: true,uploadDir:'./uploads' })) //是否默认转换 是

//引用路由
require('./config/routes')(app);
//连接数据库
mongoose.connect(dbUrl);
mongoose.set('debug',true);
//监听端口
app.listen(port);